<script type="text/javascript" src="/statics/js/jquery.lazyload.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script type="text/javascript" src="/statics/js/layer.js"></script>
<link href="/statics/css/xin.css" rel="stylesheet" type="text/css" />
<div class="ginza">
    <img src="/statics/images/ginza1.jpg" width="100%" />
    <img src="/statics/images/ginza2.jpg" width="100%" />
</div>

<div class="ginza-goods"></div>

<!--新品推荐结束-->
<div class="ginza-fixed">
	<div class="ginza-r"><a href="javascript:;" id="putSubmit">购买</a></div>
	<div class="ginza-l">
		<span class="man"></span>
		<a href="javascript:;"><div class="icon-gouwu5" id="oemCart"><span id="cartSum"></span></div></a>
		<div class="ginza-l-num" id="priceSum">￥0.00</div>
	</div>
</div>

<div class="ginza-screen"></div> 
<div class="ginza-screen2"></div> 

<div class="che-true-ginza">
	<p>已加入购物车</p>
</div>

<div class="inlevel">
    <div class="inlevel-h2">提示</div>
    <div class="inlevel-p">
		<div class="inlevel-p-w"></div>
	</div>
    <div class="inlevel-pointer">
		<a href="javascript:;" class="inlevel-a1" id="dosubmit">确认购买</a>
		<a href="javascript:;" class="inlevel-a2">继续添加</a>
	</div>
</div>

<div class="ginza-hidden">
	<div class="ginza-hidden-title"><span id="delCart">清空购物车</span>购物车</div>
	<div class="ginza-hidden-goods" id="cartGoods"></div>
</div>
<script type="text/javascript">  
			$(document).ready(function(){
				var range = 50; //距下边界长度/单位px  
				var elemt = 500; //插入元素高度/单位px  
				var maxnum = 20; //设置加载最多次数  
				var num = 1;doreturn = 1;page = 0;
				var totalheight = 0;  
				var main = $(".ginza-goods"); //主体元素  
				$(window).scroll(function(){  
					var srollPos = $(window).scrollTop(); //滚动条距顶部距离(页面超出窗口的高度)  
					totalheight = parseFloat($(window).height()) + parseFloat(srollPos);  
					if(($(document).height()-range) <= totalheight && num != maxnum && doreturn > 0) {
						doreturn = 0;$('.ajaxing').remove();
						$.get('/goods/glist',{'page':(parseInt(page)+1),'hotAjax':'1','oem':'<?=I("get.oem") ?: 0?>','sek':'<?=$sek?>','cid':'<?=I("get.cid") ?: ""?>','plv':'<?=I("get.plv")?>','new':'<?=I("get.news")?>','hot':'<?=I("get.hot")?>','sales':'<?=I("get.sales")?>','price':'<?=I("get.price")?>','keyword':'<?=I("get.keyword")?>'},function(data){
							page = data.page;
							main.append(data.data);  
							num++;doreturn = data.code;
							$(".lazys").lazyload();
						},'json');
					}  
				});  
				
			    $('#ginza-goods').append('<center class="ajaxing" style="margin-bottom:15px;"><img src="/statics/images/ajaxing.gif" /></center>');
				$.get('/goods/glist',{'page':(parseInt(page)+1),'hotAjax':'1','oem':'<?=I("get.oem") ?: 0?>','sek':'<?=$sek?>','cid':'<?=I("get.cid") ?: ""?>','plv':'<?=I("get.plv")?>','new':'<?=I("get.news")?>','hot':'<?=I("get.hot")?>','sales':'<?=I("get.sales")?>','price':'<?=I("get.price")?>','keyword':'<?=I("get.keyword")?>'},function(data){
					$('.ajaxing').remove();
					page = data.page;
					main.append(data.data);
					if(data.code == '0'){
						main.append('<p style="margin-bottom:15px;text-align:center;color:#fff;font-size:12px;">没有相关商品</p>');
					}
					num++;doreturn = 1; 
					$(".lazys").lazyload();
				},'json');
			});  
</script>
<script type="text/javascript">
	var inlevel = '<?=$inlevel?>';
	var price = 0;
	$(function(){
		var close = false;
		cartSum();
		cart();
		priceCount();
		//购买
		$('#putSubmit').click(function(){
			if((inlevel == '0' || inlevel == '1') && price > 0){
				$('.inlevel').css('display','block');
				$('.ginza-screen2').css('display','block');
			}else{
				orderSubmit();
			}
		});

		//继续添加
		$('.inlevel-a2').click(function(){
			$('.inlevel').css('display','none');
			$('.ginza-screen2').css('display','none');
		});

		//确认购买
		$('#dosubmit').click(function(){
			$('.inlevel').css('display','none');
			$('.ginza-screen2').css('display','none');
			orderSubmit();
		});

		//购物车
		$('.ginza-l a').click(function(){
			if(close == false){
				$('.ginza-hidden').animate({bottom:'40px',},800);
				$('.ginza-screen').css('display','block');
				close = true;
			}else{
				$('.ginza-hidden').animate({bottom:'-290px',},800);
				$('.ginza-screen').css('display','none');
				close = false;
			}
			cart();
		});
		$('.ginza-screen').click(function(){
			$('.ginza-hidden').animate({bottom:'-290px',},800);
			$('.ginza-screen').css('display','none');
		});
		//清空购物车
		$('#delCart').click(function(){
			delCart();
			$('.man').html('');
		});
	});
</script>
<script type="text/javascript">
	//提交订单
	function orderSubmit(){
		comb = [];
		$('#cartGoods dl').each(function(){
			comb.push($(this).find('.gid').val()+'_'+$(this).find('.num').text()+'_'+$(this).find('.bid').val());
		});
		console.log(comb);
		if(comb.length > 0 && comb != 'undefined__undefined'){
			$.get('/cart/putOrder',{'params':comb.join(',')},function(data){
				if(data.code == '1'){
					window.location = '/order/submit/params/'+data.data+'/sek/<?=I("get.sek")?>';return false;
				}else{
					layer.msg(data.msg, {icon: 0});
				}
			},'json');
		}else{
			layer.msg('需要先选择商品哦~', {icon: 0});
		}
	}
	//清空购物车
	function delCart(){
		$.get('/cart/oemDelCart',{'sek':'<?=$sek?>','type':'2'},function(data){
			if(data.code == '1'){
				$('#cartGoods').html('<dl><dd style="width:100%;text-align: center;">购物车空空如也</dd></dl>');
				cartSum();
				priceCount();
			}
		},'json');
	}
	//购物车
	function cart(){
		$.get('/cart/oemIndex',{'sek':'<?=$sek?>','type':'2'},function(data){
			var html = '';
			if(data.code == '1'){
				//$('#cartGoods');
				for(var i=0;i<data.data.length;i++){
					html += '<dl>' +
							'<dt><img src="'+data.data[i]['goods_pic']+'" width="45" /></dt>' +
							'<dd class="ginza-hidden-goods-title">'+data.data[i]['goods_title']+'</dd>' +
							'<dd class="ginza-hidden-goods-pay">￥'+data.data[i]['goods_price']+'</dd> ' +
							'<dd class="ginza-hidden-goods-num">' +
							'<span class="ginza-hidden-goods-num2" onclick="setInc(this,1)"></span><span class="num ginza-hidden-goods-num3">'+data.data[i]['goods_num']+'</span>' +
							'<span class="ginza-hidden-goods-num1" onclick="setInc(this,2)" ></span></dd>' +
							'<input type="hidden" class="gid" value="'+data.data[i]['goods_id']+'"/><input type="hidden" class="bid" value="'+data.data[i]['biz_cust_id']+'"/></dl>';
				}
			}else{
				html = '<dl><dd style="width:100%;text-align: center;">购物车空空如也</dd></dl>';
			}
			$('#cartGoods').html(html);
		},'json');
	}
	//点击增加/减少
	function setInc(_this,type){
		var Inc = $(_this).parents('dl');
		var i = 1;
		if(i == 1){
			$.get('/cart/oemEdit',{'gid':Inc.find('.gid').val(),'bid':Inc.find('.bid').val(),'type':type},function(data){
				i = 0;
				if(data.code == '1'){
					Inc.find('.num').html(data.data);
					i = 1;
				}else{
					cart();
				}
				priceCount();
				cartSum();
			},'json');
		}
	}
	//加入购物车
	function putCart(_this){
		var Id = $(_this).parent().siblings('input[type="hidden"]').val();
		$.get('/cart/putCart',{'goods_id':Id,'nums':1,'sek':'<?=$sek?>','type':'2'},function(data){
			if(data.code == '1'){
				$('.che-true-ginza').css('display','block').addClass('che-true2');
				cart();
				cartSum();
				priceCount();
				setTimeout(time,2500);
				function time(){
					$('.che-true-ginza').css('display','none');
				}
			}else{
				alert(data.msg);
			}
		},'json');
	}
	//统计购物车
	function priceCount(){
		$.get('/cart/oemCount',{'sek':'<?=$sek?>','type':'2'},function(data){
			if(data.code == '1'){
				price = data.data;
				$('#priceSum').html('￥'+(price).toFixed(2));
				if(inlevel == '1'){
					if(0 < price && price < 1000){
						$('.man').html('*满1000成为经理');
						$('.inlevel-p-w').html('购物车支付<span class="red">满1000</span>即可成为经理');
					}else if(price >= 1000){
						$('.man').html('*满1000成为经理');
						$('.inlevel-p-w').html('购物车<span class="red">已满1000</span>确认购买成为经理');
					}
				}else if(inlevel == '0'){
					if(0 < price && price < 588){
						$('.man').html('*满588成为专员');
						$('.inlevel-p-w').html('购物车支付<span class="red">满588</span>即可成为专员');
					}else if(588 <= data.data && data.data < 1588){
						$('.man').html('*满588成为专员');
						$('.inlevel-p-w').html('购物车<span class="red">已满588</span>确认购买成为专员<br/>继续购买<span class="red">满1588</span>即可成为经理');
					}else if(price >= 1588 ){
						$('.man').html('*满1588成为经理');
						$('.inlevel-p-w').html('购物车<span class="red">已满1588</span>确认购买成为经理');
					}
				}
			}else{
				$('#priceSum').html('￥0.00');
			}
		},'json');
	}
</script>
<script>
  // 注意：所有的JS接口只能在公众号绑定的域名下调用，公众号开发者需要先登录微信公众平台进入“公众号设置”的“功能设置”里填写“JS接口安全域名”。
  // 如果发现在 Android 不能分享自定义内容，请到官网下载最新的包覆盖安装，Android 自定义分享接口需升级至 6.0.2.58 版本及以上。
    wx.config({
        debug: false,
			appId: '{{$signPackage.appId}}',
			timestamp: '{{$signPackage.timestamp}}',
			nonceStr: '{{$signPackage.nonceStr}}',
			signature: '{{$signPackage.signature}}',
			jsApiList: [
				'checkJsApi',
				'onMenuShareTimeline',
				'onMenuShareAppMessage',
				'onMenuShareQQ',
				'onMenuShareWeibo'
			]
    });
</script>

<script>
    wx.ready(function () {
        var shareData = {
			title: '嗨呗公主',
			desc: '',
			link: "http://<?php echo $_SERVER['SERVER_NAME'];?>/goods/glist/oem/<?=I('get.oem') ?: 0?>/sek/<?=$sek?>",
			imgUrl: "<?=session('loginImg')?>"
    };
    wx.onMenuShareAppMessage(shareData);
    wx.onMenuShareTimeline(shareData);
    });
    wx.error(function (res) {
    });
</script>